var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("GlobalUserData"),
s = t("BroadCastMessage"),
l = t("HWSdk"),
c = t("NativeManager"),
d = t("Util"),
h = t("GoldFlyAnim"),
p = t("BoxGetView"),
u = t("HallConstant"),
f = t("ShopItem"),
m = cc._decorator,
_ = m.ccclass,
y = m.property,
g = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_boxGet = null,
        e.pfb_fly = null,
        e.gatlin = null,
        e.mecha = null,
        e.arrShop_item = new Array(5),
        e.lab_date = null,
        e.layout_item = null,
        e.arr_slide = new Array(4),
        e.videoIcon1 = null,
        e.TTVideoIcon1 = null,
        e.videoIcon2 = null,
        e.TTVideoIcon2 = null,
        e.videoIcon3 = null,
        e.TTVideoIcon3 = null,
        e._hallControl = null,
        e._shopLocalData = {
            date: 0,
            times: []
        },
        e.Shop_Base_Data = [{
            type: "gold",
            num: 2500,
            maxTimes: 10,
            freeTimes: 1,
            multiple: 6
        },
        {
            type: "diamond",
            num: 40,
            maxTimes: 5,
            freeTimes: 0,
            multiple: 6
        },
        {
            type: "box" + p.Box_Type.common,
            num: 40,
            maxTimes: 10,
            freeTimes: 1,
            multiple: 6
        },
        {
            type: "box" + p.Box_Type.middle,
            num: 30,
            maxTimes: 10,
            freeTimes: 0,
            multiple: 6
        },
        {
            type: "box" + p.Box_Type.senior,
            num: 15,
            maxTimes: 10,
            freeTimes: 0,
            multiple: 6
        }],
        e._closeCallBack = null,
        e.slideIndex = 0,
        e.switchCar = function() {
            var t, e, o, i = this;
            this.isCarShow ? (t = 1.5, e = 0, o = 255) : (t = 2, e = 255, o = 0),
            this.isCarShow = !this.isCarShow,
            this.scheduleOnce(function() {
                cc.tween(i.gatlin).to(.5, {
                    opacity: e
                }).start(),
                cc.tween(i.mecha).to(.5, {
                    opacity: o
                }).call(function() {
                    i.switchCar()
                }).start()
            },
            t)
        },
        e._shopItem = [],
        e.nIntervalHandle = 0,
        e
    }
    return n(e, t),
    e.prototype.onLoad = function() {
        d.Util.is_tt() && (this.videoIcon1.active = !1, this.TTVideoIcon1.active = !0, this.videoIcon2.active = !1, this.TTVideoIcon2.active = !0, this.videoIcon3.active = !1, this.TTVideoIcon3.active = !0),
        this.initShopData(),
        this.updateView(),
        this.initTime();
        for (var t = 1; t < this.arr_slide.length; t++) this.arr_slide[t].opacity = 0;
        this.slideShow()
    },
    e.prototype.onEnable = function() {
        d.Util.hideNativeBanner(),
        d.Util.hideHallBanner(),
        l.default.Ins.showNativeInsertAd(),
        d.Util.is_VIVO() ? (d.Util.showBanner(), d.Util.showNativeGridAd()) : d.Util.hideBanner(),
        d.Util.is_233() && c.default.instance.showFullVideoAd()
    },
    e.prototype.onDisable = function() {
        l.default.Ins.hideNativeInsertAd()
    },
    e.prototype.initView = function(t, e) {
        this._hallControl = t,
        this._closeCallBack = e
    },
    e.prototype.slideShow = function() {
        var t = this,
        e = this.arr_slide[this.slideIndex];
        this.slideIndex = this.slideIndex + 1 >= this.arr_slide.length ? 0 : this.slideIndex + 1;
        var o = this.arr_slide[this.slideIndex];
        this.scheduleOnce(function() {
            cc.tween(e).to(.5, {
                opacity: 0
            }).start(),
            cc.tween(o).to(.5, {
                opacity: 255
            }).call(function() {
                t.slideShow()
            }).start()
        },
        2)
    },
    e.prototype.initShopData = function() {
        this._shopLocalData = {
            date: 0,
            times: []
        },
        this._shopLocalData.times = [];
        var t = cc.sys.localStorage.getItem("user_shop_data");
        if (t) {
            var e = JSON.parse(t);
            this._shopLocalData.date = Number(e.date);
            for (var o = 0; o < e.times.length; o++) this._shopLocalData.times.push(e.times[o])
        } else for (this._shopLocalData.date = 0, o = 0; o < this.Shop_Base_Data.length; o++) this._shopLocalData.times.push(0)
    },
    e.prototype.saveShopData = function(t) {
        if (t) {
            this._shopLocalData.date = 0,
            this._shopLocalData.times.length = 0;
            var e = new Date,
            o = e.getMonth() + 1,
            i = o < 10 ? "0" + o: "" + o,
            n = e.getDate(),
            a = n < 10 ? "0" + n: "" + n,
            r = Number(e.getFullYear() + i + a);
            this._shopLocalData.date = r;
            for (var s = 0; s < this.Shop_Base_Data.length; s++) this._shopLocalData.times.push(0)
        }
        this.updateView(),
        cc.sys.localStorage.setItem("user_shop_data", JSON.stringify(this._shopLocalData))
    },
    e.prototype.initTime = function() {
        var t = new Date,
        e = t.getMonth() + 1,
        o = e < 10 ? "0" + e: "" + e,
        i = t.getDate(),
        n = i < 10 ? "0" + i: "" + i;
        Number(t.getFullYear() + o + n) > this._shopLocalData.date && this.saveShopData(!0),
        this.onSetTime()
    },
    e.prototype.updateView = function() {
        for (var t = 0; t < this.Shop_Base_Data.length; t++) this._shopItem[t] || (this._shopItem[t] = this.createShopItem(t)),
        this._shopItem[t].updateItem(t, this.Shop_Base_Data[t], this._shopLocalData.times[t])
    },
    e.prototype.createShopItem = function(t) {
        return this.arrShop_item[t].getComponent(f.default).init(this),
        this.arrShop_item[t].getComponent(f.default)
    },
    e.prototype.onSetTime = function() {
        var t = this,
        e = function() {
            var e = new Date,
            o = e.setDate(e.getDate() + 1),
            i = new Date(o),
            n = i.getFullYear(),
            a = i.getMonth(),
            r = i.getDate(),
            s = (new Date(n, a, r, 0, 0, 0).getTime() - new Date().getTime()) / 1e3,
            l = Math.floor(s % 60),
            c = Math.floor(s / 60 % 60),
            d = Math.floor(s / 3600);
            t.lab_date.string = d + "小时" + c + "分钟" + l + "秒",
            l <= 0 && c <= 0 && l <= 0 && t.saveShopData(!0)
        };
        this.nIntervalHandle = setInterval(e, 1e3),
        e()
    },
    e.prototype.onBtnClose = function() {
        r.default.isShopView = !1,
        this.playAudio(u.Audio_ID.btn_click),
        this._closeCallBack && this._closeCallBack(),
        this._hallControl.onSetOwnGold(),
        this._hallControl.onSetOwnDiamond(),
        clearInterval(this.nIntervalHandle),
        this.node.destroy(),
        this._hallControl.comebackshow(),
        d.Util.is_qg() && !r.default.isIllustratedBookView && d.Util.showHallBanner(),
        d.Util.is_VIVO() && r.default.isIllustratedBookView,
        d.Util.hideBanner(),
        r.default.bAuditMode || r.default.isIllustratedBookView ? d.Util.hideNativeGridAd() : d.Util.is_VIVO() && !r.default.bAuditMode && d.Util.showNativeGridAd()
    },
    e.prototype.onGet = function(t, e, o, i) {
        switch (this._shopLocalData.times[t]++, this.saveShopData(!1), h.Fly_Type.Default, e) {
            case "gold":
                h.Fly_Type.Gold,
            this.onGetGold(t, o);
            break;
            case "diamond":
                h.Fly_Type.Diammond,
            this.onGetDiamond(t, o);
            break;
            case "box" + p.Box_Type.common: r.default.addOpenShopCommonBoxNum(),
            this.onGetBox(p.Box_Type.common);
            break;
            case "box" + p.Box_Type.middle: r.default.addOpenShopEpicBoxNum(),
            this.onGetBox(p.Box_Type.middle);
            break;
            case "box" + p.Box_Type.senior: r.default.addOpenShopLegendBoxNum(),
            this.onGetBox(p.Box_Type.senior);
        }
        i && i()
    },
    e.prototype.onVideo = function(t, e, o, i, n) {
        var a = this;
        r.default.videoTab = i,
        d.Util.showRewardVideo(function() {
            setTimeout(function() {
                a.onGet(t, e, o, n)
            },
            1e3)
        },
        null, null, e == "box" + p.Box_Type.common)
    },
    e.prototype.onGetGold = function(t, e) {
        var o = this;
        r.default.saveGoldData(!0, e),
        this.playAudio(u.Audio_ID.get_gold),
        d.Util.AnimFly(h.Fly_Type.Gold, this.pfb_fly, this._shopItem[t].getIconNode(), this._hallControl.getGoldWorldPos(),
        function() {
            o._hallControl.onSetOwnGold(!0)
        },
        function() {})
    },
    e.prototype.onGetDiamond = function(t, e) {
        var o = this;
        r.default.saveDiamondData(!0, e),
        this.playAudio(u.Audio_ID.get_gold),
        d.Util.AnimFly(h.Fly_Type.Diammond, this.pfb_fly, this._shopItem[t].getIconNode(), this._hallControl.getDiamondWorldPos(),
        function() {
            o._hallControl.onSetOwnDiamond(!0)
        },
        function() {})
    },
    e.prototype.onGetBox = function(t) {
        var e = cc.instantiate(this.pfb_boxGet);
        this._hallControl.node.addChild(e, 100),
        e.getComponent(p.default).showOpenBoxView(t, this._hallControl)
    },
    e.prototype.playAudio = function(t) {
        this._hallControl ? this._hallControl.playAudio(t) : s.default.getInstance().SendMessage(u.Broadcast_Func.Audio, t)
    },
    a([y(cc.Prefab), y(cc.Prefab)], e.prototype, "pfb_boxGet", void 0),
    a([y(cc.Prefab)], e.prototype, "pfb_fly", void 0),
    a([y(cc.Node)], e.prototype, "gatlin", void 0),
    a([y(cc.Node)], e.prototype, "mecha", void 0),
    a([y(cc.Node)], e.prototype, "arrShop_item", void 0),
    a([y(cc.Label)], e.prototype, "lab_date", void 0),
    a([y(cc.Layout)], e.prototype, "layout_item", void 0),
    a([y([cc.Node])], e.prototype, "arr_slide", void 0),
    a([y(cc.Node)], e.prototype, "videoIcon1", void 0),
    a([y(cc.Node)], e.prototype, "TTVideoIcon1", void 0),
    a([y(cc.Node)], e.prototype, "videoIcon2", void 0),
    a([y(cc.Node)], e.prototype, "TTVideoIcon2", void 0),
    a([y(cc.Node)], e.prototype, "videoIcon3", void 0),
    a([y(cc.Node)], e.prototype, "TTVideoIcon3", void 0),
    a([_], e)
} (cc.Component);
o.default = g